package com.chenhao.springcloud.chenhaodatastructureservice.recursion;

/**
 * Description:递归运算,将原问题转换成更小的问题
 *
 * @author chenhao
 * @date 2020/12/10 10:08
 */
public class Sum {
    public static int sum(int[] arr){
        return sum(arr,0);
    }

    private static int sum(int [] arr, int l){
        if (l==arr.length){
            return 0;
        }
        return arr[l]+sum (arr,l+1);
    }

    public static void main(String[] args) {
        int[] nums = {1,3,4,5,6,7,8,9};
        System.out.println(sum(nums));
    }
}
